﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace BesAsm.Emgaats.Core
{
  /// <summary>
  /// A keyed collection of EmgaatsLayer objects, using LibraryItem as the key
  /// </summary>
  public class EmgaatsLayerCollection : KeyedCollection<LibraryItem, EmgaatsLayer>
  {
    public EmgaatsLayerCollection()
      :base()
    {
    }

    /// <summary>
    /// Type-specific indexer for working around bug for XmlSerializer call to 
    /// object IList.this[int index] instead of type-specific indexer. See
    /// www.pluralsight-training.net/community/blogs/craig/archive/2005/10/19/15696.aspx
    /// </summary>
    /// <param name="index">Index of item</param>
    /// <returns>The desired EmgaatsLayer</returns>
    public new EmgaatsLayer this[int index]
    {
      get
      {
        return ((IList<EmgaatsLayer>)this)[index];
      }
    }
    /// <summary>
    /// Initializes a new instance of the <see cref="EmgaatsLayerCollection"/> class based on an existing
    /// collection of EmgaatsLayer objects.
    /// </summary>
    /// <param name="existingCollection">An existing collection.</param>
    public EmgaatsLayerCollection(IEnumerable<EmgaatsLayer> existingCollection)
      :base()
    {
      foreach (EmgaatsLayer layer in existingCollection)
      {
        this.Add(layer);
      }
    }

    /// <summary>
    /// Identifies the EmgaatsLayer property to use as this collection's key
    /// </summary>
    /// <param name="item">A LibraryItem used to return an EmgaatsLayer from this collection</param>
    /// <returns>The EmgaatsLayer with whose LibraryItem is <see cref="item"/>item</returns>
    protected override LibraryItem GetKeyForItem(EmgaatsLayer item)
    {
      return item.LibraryItem;
    }
  }
}
